﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmartMathLibrary
{
    /// <summary>
    /// Defines a function delegate to bind the method, which represents the bivariate real 
    /// function with two real arguments.
    /// </summary>
    public delegate double HardBivariateRealFunctionPointer(double a, double b);

    /// <summary>
    /// This class represents a bivariate function, which can be implemented by source code.
    /// </summary>
    [Serializable]
    public class HardBivariateRealFunction : IHardBivariateRealFunction
    {
        /// <summary>
        /// The pointer to the method, which represents the function.
        /// </summary>
        private HardBivariateRealFunctionPointer hardRealFunctionPointer;

        /// <summary>
        /// Initializes a new instance of the <see cref="HardBivariateRealFunction"/> class.
        /// </summary>
        /// <param name="hardRealFunctionPointer">The pointer to the method, which represents the function.</param>
        public HardBivariateRealFunction(HardBivariateRealFunctionPointer hardRealFunctionPointer)
        {
            this.hardRealFunctionPointer = hardRealFunctionPointer;
        }

        /// <summary>
        /// Gets or sets the pointer to the method, which represents the function.
        /// </summary>
        /// <value>The pointer to the method, which represents the function.</value>
        public HardBivariateRealFunctionPointer HardRealFunctionPointer
        {
            get { return hardRealFunctionPointer; }
            set { hardRealFunctionPointer = value; }
        }

        /// <summary>
        /// Calculates the function at the specified values a and b.
        /// </summary>
        /// <param name="a">The first parameter of the function.</param>
        /// <param name="b">The second parameter of the function.</param>
        /// <returns>
        /// The result of the function at the specified values a and b.
        /// </returns>
        public double SolveAt(double a, double b)
        {
            return this.hardRealFunctionPointer(a, b);
        }
    }
}